﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApp1.Service;
using WpfApp1.Services;

namespace WpfApp1.ucontrol
{
    /// <summary>
    /// RegisterView.xaml 的交互逻辑
    /// </summary>
    public partial class RegisterView 
    {
        public RegisterView()
        {
            InitializeComponent();
        }

        private async  void Button_Click(object sender, RoutedEventArgs e)
        {
            var httpRestClient=new HttpRestClient();
            LoginUserService loginUserService = new LoginUserService(httpRestClient);
            var accountStr = account.Text;
            var pwdStr= pwd.Password;
            var codeStr= txtcode.Text;
            if(string.IsNullOrEmpty(accountStr))
            {
                Growl.Error("手机号不能为空");
                return;
            }
            if (string.IsNullOrEmpty(codeStr))
            {
                Growl.Error("验证码不能为空");
                return;
            }
            if (string.IsNullOrEmpty(pwdStr))
            {
                Growl.Error("密码不能为空");
                return;
            }
           var regResult=  await loginUserService.UserReg(new UserRegDto { Code = codeStr, password = pwdStr, Phone = accountStr });
            if(regResult.Code==200)
            {
                Growl.Success("注册成功");
               
            }
            else
            {
                Growl.Error(regResult.Msg);
            }

        }

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var httpRestClient = new HttpRestClient();
            LoginUserService loginUserService = new LoginUserService(httpRestClient);
            var accountStr = account.Text;        
            if (string.IsNullOrEmpty(accountStr))
            {
                Growl.Error("手机号不能为空");
                return;
            }
            var regResult = await loginUserService.SendCode( accountStr );
            if (regResult.Code == 200)
            {
                sendbtn.Content= "已发送";
                //sendbtn.IsEnabled = false;

            }
            else
            {
                Growl.Error(regResult.Msg);
            }
        }
    }
}
